package com.scs.application.modules.device.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.consts.SerialKeys;
import com.scs.application.core.exception.BusinessException;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.device.entity.DeviceWorkOffer;
import com.scs.application.modules.device.mapper.DeviceWorkOfferMapper;
import com.scs.application.modules.device.service.DeviceWorkOfferService;
import com.scs.application.modules.purchase.entity.Order;
import org.springframework.stereotype.Service;
import com.scs.application.core.service.BaseServiceImpl;
/**
 *  采购报价明细 服务实现类
 */
@Service
public class DeviceWorkOfferServiceImpl extends BaseServiceImpl<DeviceWorkOfferMapper, DeviceWorkOffer> implements DeviceWorkOfferService {

    @Override
    public boolean saveOrUpdate(DeviceWorkOffer entity) {
        if (entity.isNewRecord()) {
            BusinessException.throwErrorIf(
                    this.count(Wrappers.<DeviceWorkOffer>query().eq("work_item_id",entity.getWorkItemId()).eq("supplier_id",entity.getSupplierId())) > 0,
                    "已存在供应商【%s】的报价，请勿重复添加",
                    entity.getSupplierName()
            );
            if (entity.getFlagBid() == null) {
                entity.setFlagBid(false);
            }
        }

        return super.saveOrUpdate(entity);
    }
}